//
// Created by liushuai on 2020/4/2.
//
#include "maxProfit.h"
int maxProfit(vector<int>& prices){
    int length = prices.size();
    int result = 0;
    if(length<=1){
        return 0;
    }else{
        int cache = 0;
        int min_value = prices.at(0);
        for(int i=0;i<length;i++){
            if(prices.at(i)<min_value){
                min_value = prices.at(i);
            }
            result = max(cache,prices.at(i)-min_value);
            cache = result;
        }
        return result;
    }

}
